package com.sundaying.gooway.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.opensymphony.xwork2.ActionSupport;
import com.sundaying.gooway.entity.TopItem;
import com.sundaying.gooway.entity.UrlClass;
import com.sundaying.gooway.entity.UrlItem;
import com.sundaying.gooway.service.TopItemService;
import com.sundaying.gooway.service.UrlClassService;
import com.sundaying.gooway.service.UrlItemService;
import com.sundaying.gooway.vo.ClassUrlItem;

public class IndexAction extends ActionSupport {
	private TopItemService topItemService;
	private UrlClassService urlClassService;
	private UrlItemService urlItemService;

	private List<ClassUrlItem> classUrlItemList;
	private List<ClassUrlItem> classUrlItemList_cool;
	private List<UrlItem> urlItemList_news;
	private List<UrlItem> urlItemList_friend;
	private List<UrlItem> urlItemList_search;
	private List<UrlItem> urlItemList_cool;

	public TopItemService getTopItemService() {
		return topItemService;
	}

	@Resource
	public void setTopItemService(TopItemService topItemService) {
		this.topItemService = topItemService;
	}

	public UrlClassService getUrlClassService() {
		return urlClassService;
	}

	@Resource
	public void setUrlClassService(UrlClassService urlClassService) {
		this.urlClassService = urlClassService;
	}

	public UrlItemService getUrlItemService() {
		return urlItemService;
	}

	@Resource
	public void setUrlItemService(UrlItemService urlItemService) {
		this.urlItemService = urlItemService;
	}

	public List<ClassUrlItem> getClassUrlItemList() {
		return classUrlItemList;
	}

	public void setClassUrlItemList(List<ClassUrlItem> classUrlItemList) {
		this.classUrlItemList = classUrlItemList;
	}

	public List<UrlItem> getUrlItemList_news() {
		return urlItemList_news;
	}

	public void setUrlItemList_news(List<UrlItem> urlItemList_news) {
		this.urlItemList_news = urlItemList_news;
	}

	public List<UrlItem> getUrlItemList_friend() {
		return urlItemList_friend;
	}

	public void setUrlItemList_friend(List<UrlItem> urlItemList_friend) {
		this.urlItemList_friend = urlItemList_friend;
	}

	public List<UrlItem> getUrlItemList_search() {
		return urlItemList_search;
	}

	public void setUrlItemList_search(List<UrlItem> urlItemList_search) {
		this.urlItemList_search = urlItemList_search;
	}

	public List<UrlItem> getUrlItemList_cool() {
		return urlItemList_cool;
	}

	public void setUrlItemList_cool(List<UrlItem> urlItemList_cool) {
		this.urlItemList_cool = urlItemList_cool;
	}

	public List<ClassUrlItem> getClassUrlItemList_cool() {
		return classUrlItemList_cool;
	}

	public void setClassUrlItemList_cool(
			List<ClassUrlItem> classUrlItemList_cool) {
		this.classUrlItemList_cool = classUrlItemList_cool;
	}

	public String init() {
		try {
			// 热点URL分类
			classUrlItemList = new ArrayList<ClassUrlItem>();
			// 酷站分类
			classUrlItemList_cool = new ArrayList<ClassUrlItem>();

			List<UrlClass> urlClassList = topItemService.getTopUrlClassList(1,
					20);
			int i = 0;
			for (UrlClass urlClass : urlClassList) {
				i++;
				List<UrlItem> urlItemList = topItemService.getTopUrlItemList(2,
						50, urlClass.getId());
				if (urlItemList == null) {
					continue;
				}

				ClassUrlItem classUrlItem = new ClassUrlItem();
				if (i < 7) {
					classUrlItem.setUrlClass(urlClass);
					classUrlItem.setUrlItemList(urlItemList);
					classUrlItemList.add(classUrlItem);
				} else {
					classUrlItem.setUrlClass(urlClass);
					classUrlItem.setUrlItemList(urlItemList);
					classUrlItemList_cool.add(classUrlItem);
				}
			}

			// 资讯列表
			urlItemList_news = topItemService.getTopUrlItemList(3, 30);
			urlItemList_friend = topItemService.getTopUrlItemList(4, 6);
			urlItemList_search = topItemService.getTopUrlItemList(5, 8);
			urlItemList_cool = topItemService.getTopUrlItemList(4, 16);

		} catch (Exception e) {
			System.out.println(e.getMessage());
			return this.ERROR;
		}

		return this.SUCCESS;
	}
}
